package com.shop.dao.impl;

import org.apache.ibatis.session.SqlSession;

import com.shop.dao.FavoriteDao;
import com.shop.domain.Favorite;
import com.shop.util.MyBatisUtil;

/**
 * 
 * @author wenjuanhenxing
 * @version V1.0 FavoriteDaoImpl.java 2016-2-11 上午7:35:03
 */
public class FavoriteDaoImpl implements FavoriteDao {

	@Override
	public boolean addFavorite(Favorite favorite) {
		if (favorite == null) {
			return false;
		}
		SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
		int rowsAffected = sqlSession.insert(
				"com.shop.dao.mapping.FavoriteMapper" + ".addFavorite",
				favorite);
		MyBatisUtil.closeSession(sqlSession);
		return rowsAffected == 1;
	}

	@Override
	public boolean deleteFavoriteById(Long id) {
		SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
		int rowsAffected = sqlSession.delete(
				"com.shop.dao.mapping.FavoriteMapper" + ".deleteFavoriteById",
				id);
		MyBatisUtil.closeSession(sqlSession);
		return rowsAffected == 1;
	}

}
